/**
 * Created by gaoyj on 2018/7/3.
 */
window.onload = function (ev) {
    topbar.hide();
};
var faceForm = $("#faceForm").validate({
    rules: {
        adminName: {
            required: true
        },
        adminAccount:{
            required: true
        }
    }
});
$('#dataTable').bootstrapTable({
    url: '/outerAdmin/queryOuterAdmin',
    height: $(window).height() - 200,
    pageSize: 30,
    pagination: true,
    pageList: [30, 50, 100],
    clickToSelect: true,
    queryParams: queryParams,
    uniqueId: 'id',
    queryParamsType: '',
    sidePagination: 'server',
    responseHandler: function (res) {
        return {
            "total": res.data.total,
            "rows": res.data.list
        };
    },
    columns: [
        {
            width: '3px',
            align: 'center',
            formatter: function (v, row, index) {
                return index + 1
            }
        }, {
            width: '40px',
            align: 'center',
            field: 'adminName',
            title: '管理员名称'
        },{
            width: '40px',
            align: 'center',
            field: 'adminAccount',
            title: '管理员账号'
        },{
            width: '40px',
            align: 'center',
            field: 'outerType',
            title: '管理员类型',
            formatter: function (v, row, index) {
                return outerTypeFun[v];
            }
        }, {
            width: '20px',
            align: 'center',
            field: 'adminStatus',
            title: '管理员状态',
            formatter: function (v, row, index) {
                return proxyStatusFun[v];
            }
        }, {
            width: '40px',
            align: 'center',
            field: 'createTime',
            title: '创建时间',
            formatter: function (v, row, index) {
                var createTime = v == null ? "-" : changeDateFormat(v).substr(5)
                return createTime;
            }
        }, {
            width: '40px',
            align: 'center',
            field: 'modifyTime',
            title: '修改时间',
            formatter: function (v, row, index) {
                var modifyTime = v == null ? "-" : changeDateFormat(v).substr(5)
                return modifyTime;
            }
        }
    ]
});

$("#search").click(function () {
    $("#dataTable").bootstrapTable("refresh");
});
$("#updateBtn").click(function () {
    var v=$("#faceForm").valid();
    if(!v){
        return;
    }
    $.ajax({
        type: "POST",
        url: "/outerAdmin/createOuterAdmin",
        traditional: true,
        data: $("#faceForm").serialize(),
        dataType: "json",
        success: function (data) {
            if(data.errorCode==200){
                $("#dataTable").bootstrapTable("refresh");
                layer.msg("新增成功");
                $("#myModal").modal("hide");
            }else {
                layer.msg(data.errorMsg)
            }
        },
        beforeSend: function () {
        }
    });
})
function addManager() {
    $("#faceForm input").val("");
    faceForm.resetForm();
    $("#JSESSIONID").val(sessionStorage.getItem('JSESSIONID'));
    $("#myModal").modal("show");
}
function queryParams(params) {
    return {
        pageSize: params.pageSize,
        pageNumber: params.pageNumber,
        adminName: $.trim($("#adminName").val()),
        outerType: $.trim($("#outerType").val()),
        adminStatus: $("#adminStatus").val(),
    };
}